package com.example.wnn;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.domain.AlipayFundTransToaccountTransferModel;
import com.alipay.api.request.AlipayFundTransToaccountTransferRequest;
import com.alipay.api.response.AlipayFundTransToaccountTransferResponse;

import com.alipay.api.FileItem;
import java.util.Base64;
import java.util.ArrayList;
import java.util.List;

public class AlipayFundTransToaccountTransfer2 {

    public static void main(String[] args) throws AlipayApiException {
        // 初始化SDK
        AlipayClient alipayClient = new DefaultAlipayClient(getAlipayConfig());

        // 构造请求参数以调用接口
        AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest();
        AlipayFundTransToaccountTransferModel model = new AlipayFundTransToaccountTransferModel();

        // 设置收款方账户
        model.setPayeeAccount("hxgdno1795@sandbox.com");

        // 设置转账金额
        model.setAmount("12.23");

        // 设置收款方真实姓名（最长支持100个英文/50个汉字）
        model.setPayeeRealName("");

        // 设置转账备注（支持200个英文/100个汉字）
        model.setRemark("转账备注");

        // 设置商户转账唯一订单号
        model.setOutBizNo("314232142343222");

        // 设置收款方账户类型
        model.setPayeeType("ALIPAY_LOGONID");

        // 设置付款方姓名（最长支持100个英文/50个汉字）
        model.setPayerShowName("上海交通卡退款");

        request.setBizModel(model);
        AlipayFundTransToaccountTransferResponse response = alipayClient.execute(request);
        System.out.println(response.getBody());

        if (response.isSuccess()) {
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
            // sdk版本是"4.38.0.ALL"及以上,可以参考下面的示例获取诊断链接
            // String diagnosisUrl = DiagnosisUtils.getDiagnosisUrl(response);
            // System.out.println(diagnosisUrl);
        }
    }

    private static AlipayConfig getAlipayConfig() {
        String privateKey  = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDCX+TxPhVleUY/sluEQGWnmzxthPoHUwVycAd9VEh63z5sEjNzCVF/p8eLK4J9j3kFW+n4DEVEEev9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i9UgNxkRA17O/AerPs5M09dfG5Hcd9xruICjdok1kQKBgQCHAeobcafDBHBnXeQeZNKAxJ4rhSDZ5Df/oMiAzqfMF4IzFnSfWBl0Fs4pw5DxMNXp/4gyF29wAJcdVfPJtmrES8AaDQkmULx1wdnSuDVGnUi+J6jV5X+nCnpwwn+2NLtWjcCbIWR1QUbl64+DB1diybNIlGY3+o0KeclmIyjPoQKBgBV/hB31ULdnY5n6PkXZr4MuPCAEZus4NjdhMCkqjymPrJqSLRjux40gCpjdpaXFP/UybIL6Ae7ZSIYoDeo3SK9FNoeeKtA1X2648MP5fUjBE4PJi32MsVxNSLhslupCaBEyq9Dfaf0rHpoB0+ixGNLPJHx+GambYpPMeT+/RUi2";
        String alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoMObIwGOIe0C2xAOm+W42sOqpICd8l4iexnZcf9+k34SUeO6Q8sN7fii0VquykRWoZ48LoufOdHSQ1tFH3mNQIggyG/2uO+zM9/l1sOpur8x+P8Mmti4Zy8H3U/4ntWbzjCxx50v0OgYxxVj3n8XcO6An8wH9CUyhJlqkxY45PSjKuHFPvVX6/+OUSWE+J7rnrpHwnnwito0J4Bj7KAnhvXpzkDHYJQYaUXzRa8FOPCNyuVLX4xVJOlOnThuORTNUFtbNVuzX1vhTecHIiL4972bA3Co7jENf+nOzrEe1Hs7OISFJkcN4X+q6/pKFESF/FOMoevydUtAdOQcIvLN2QIDAQAB";
        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setServerUrl("https://openapi-sandbox.dl.alipaydev.com/gateway.do");
        alipayConfig.setAppId("9021000122694421");
        alipayConfig.setPrivateKey(privateKey);
        alipayConfig.setFormat("json");
        alipayConfig.setAlipayPublicKey(alipayPublicKey);
        alipayConfig.setCharset("UTF-8");
        alipayConfig.setSignType("RSA2");
        return alipayConfig;
    }
}